package com.yc.blog.listener;

import java.io.File;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import com.yc.blog.util.FileUploadUtil;
import com.yc.blog.util.StringUtil;



/**
 * Application Lifecycle Listener implementation class ApplicationListener
 *
 */
@WebListener
public class ApplicationListener implements ServletContextListener {

    public void contextDestroyed(ServletContextEvent sce)  { 
    	
    }

    public void contextInitialized(ServletContextEvent arg)  { 
         String path = arg.getServletContext().getInitParameter("uploadPath");
         if(StringUtil.chekNUll(path)) {
        	 path = "blog_pics";
         }
         
         String basePath = arg.getServletContext().getRealPath("/");
         File fl = new File(basePath,path);
         if(!fl.exists()) {
        	 fl.mkdirs();
         }
         
         FileUploadUtil.PATH = path;
    }
	
}
